Return to Computer Vision Notebooks

Compositing Operators



Methods for combining and mixing images.

0. Input images


Given the input images $A$ and $B$ (sRGB colorspace).

p.s.: All the input images are normalized between 0-1.

1. Alpha compositing operators


1.1. Over


$$ \large O = A\alpha+B(1-\alpha) $$

1.2. Atop


$$ \large O = A\beta+B(1-\alpha) $$

1.3. Conjoint over


$$ \large O = \begin{cases} A &, \text{if } \alpha > \beta \\ A+\frac{B(1-\alpha)}{\beta} &, \text{otherwise} \end{cases} $$

1.4. Disjoint over


$$ \large O = \begin{cases} A+B &, \text{if } \alpha+\beta < 1 \\ A+\frac{B(1-\alpha)}{\beta} &, \text{otherwise} \end{cases} $$

1.5. In


$$ \large O = A\beta $$

1.6. Xor


$$ \large O = A(1 - \beta) + B(1 - \alpha) $$

2. Blend modes


Due the input images are in sRGB colorspace, it is necessary to linearize them by the $\gamma = 2.2$ before operating and the output must be transformed to sRGB by inverting the $\gamma$.

$$ \large I' = I^{\gamma} \quad ; \quad O' = O^{\frac{1}{\gamma}} $$

2.1. Average


$$ \large O' = \frac{A'+B'}{2} $$

2.2. Color burn


$$ \large O' = 1 - \frac{1-B'}{A'} $$

2.4. Difference


$$ \large O' = |A'-B'| $$

2.5. Division


$$ \large O' = \frac{A'}{B'} $$

2.6. Exclusion


$$ \large O' = A'+B'-2A'B' $$

2.7. From


$$ \large O' = B'- A' $$

2.8. Geometric


$$ \large O' = \frac{2A'B'}{A'+B'} $$

2.9. Hypot


$$ \large O' = \sqrt{A'^2+B'^2} $$

2.10. Max


$$ \large O' = \max(A', B') $$

2.11. Min


$$ \large O' = \min(A', B') $$

2.12. Minus


$$ \large O' = A'- B' $$

2.13. Multiply


$$ \large O' = A'B' $$

2.14. Plus


$$ \large O' = A' + B' $$

2.15. Screen


$$ \large O' = A' + B' - A'B' $$

2.16. Soft light


$$ \large O' = B'(2A' + B'(1 - A'B')) $$

2.17. Hard light


$$ \large O' = \begin{cases} \text{multiply}&, \text{if } A < \frac{1}{2} \\ \text{screen}&, \text{otherwise} \end{cases} $$

2.18. Overlay


$$ \large O' = \begin{cases} \text{multiply}&, \text{if } B < \frac{1}{2} \\ \text{screen}&, \text{otherwise} \end{cases} $$